package org.example.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PerformanceAspect {

    // 环绕增强：统计方法执行时间
    @Around("execution(* org.example.service.OrderService.*(..))")
    public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();  // 开始时间
        Object result = joinPoint.proceed();  // 执行目标方法
        long endTime = System.currentTimeMillis();    // 结束时间

        String methodName = joinPoint.getSignature().getName();
        System.out.println("方法 " + methodName + " 执行时间: " + (endTime - startTime) + "毫秒");
        return result;
    }
}
